<?
function show_catalogues($catalogues, $level){
    foreach($catalogues as $catalogue){
        $id = Arr::get($catalogue, 'id', 0);
        $hide = (Arr::get($catalogue, 'hide') == 'hide') ? 'class="hide"':'';
        $padding_left = 'style="padding-left:'.($level*30 + 10).'px;"';
        echo "<tr $hide>
                <td></td>
                <td $padding_left><b>{$catalogue['name']}</b><br/>
                    <a href=\"{$catalogue['href']}\" target=\"_blank\">{$catalogue['href']}</a>
                </td>";
        if(isset($catalogue['subcatalogues'])){
            echo "<td>{$catalogue['products']}</td>";
        } else {            
            echo "<td><a class=\"action\" href=\"/admin/catalogue/product_add?id=$id\" title=\"Добавить позицию\">+</a>
                      <a href=\"/admin/catalogue/product?id=$id\" title=\"Просмотреть позиции\">{$catalogue['products']}</a>                      
                  </td>";
        }
        echo   "<td>
                    <a href=\"/admin/catalogue/add?id=$id\"  class=\"add action\" title=\"Добавить подкаталог\">+</a>
                    <a href=\"/admin/catalogue/up?id=$id\" class=\"action\" title=\"Поднять каталог\">&uarr;</a>
                    <a href=\"/admin/catalogue/down?id=$id\" class=\"action\" title=\"Опустить каталог\">&darr;</a>                    
                    <a href=\"/admin/catalogue/hide?id=$id\" title=\"Скрыть/отобразить каталог\">hide/show</a>
                    <a href=\"/admin/catalogue/edit?id=$id\" title=\"Редактировать\">edit</a>
                    <a href=\"/admin/catalogue/delete?id=$id\" title=\"Удалить\">delete</a>                    
                </td>
              </tr>";
        if(isset($catalogue['subcatalogues'])){
            echo show_catalogues($catalogue['subcatalogues'], $level + 1);    
        }
    }
}
?>

<table>
    <tr><th><a class="action" href="/admin/catalogue/add">+</a></th>
        <th>Разделы каталога</th>
        <th style="width:50px">Товаров</th>
        <th style="width:180px">Действия</th>
    </tr>
    <? show_catalogues($catalogues, 0); ?> 
</table>

       